package nicg.st.service;

import org.springframework.stereotype.Service;

import com.google.protobuf.InvalidProtocolBufferException;

import nicg.st.msg.ProtoTarget;

@Service
public class TargetService {
	public byte[] findPBTargetByteByNum(long targetNum) {
		ProtoTarget.Target_Info.Builder builder2=ProtoTarget.Target_Info.newBuilder();
		ProtoTarget.Targets.Builder builder3=ProtoTarget.Targets.newBuilder();
		//做个测试数据，使用者可访问数据库或文件得到
		if (targetNum==1001) {
			System.out.println("1001------------------------------");
			builder2.setTarIndex(1001).setTarName("侦察机").setTarLatitude((float)(110.13))
			.setTarLongitude((float)(87.5)).setTarElevation((float)(118.13));
		}
		if (targetNum==1002) {
			builder2.setTarIndex(1002).setTarName("无人机").setTarLatitude((float)(90.13))
			.setTarLongitude((float)(110.5)).setTarElevation((float)(1000.13));
		}
		builder3.addTars(builder2);
		ProtoTarget.Target_Info target_Info=builder2.build();
		byte[]b=target_Info.toByteArray();
		return b;
	}
	

	public byte[] findPBTargetByArea(byte[] input) {
//		System.out.println(input);
		ProtoTarget.Target_Search target_Search;
		try {
			target_Search = ProtoTarget.Target_Search.parseFrom(input);
		} catch (InvalidProtocolBufferException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return  null;
		}
		ProtoTarget.Target_Info.Builder builder2=ProtoTarget.Target_Info.newBuilder();
		ProtoTarget.Targets.Builder builder3=ProtoTarget.Targets.newBuilder();
		System.out.println("输入222222："+ target_Search.getPointLatitude() + "   " + target_Search.getPointLongitude() + "   " + target_Search.getRadius());

		if (target_Search.getPointLatitude()<=80.11 && target_Search.getPointLongitude()<=102.12 && target_Search.getRadius()<=103.13) {
	//		System.out.println("1001------------------------------");
			builder2.setTarIndex(1001).setTarName("侦察机").setTarLatitude((float)(110.13))
			.setTarLongitude((float)(87.5)).setTarElevation((float)(118.13)).setTarType(ProtoTarget.Type.KZ);
			builder3.addTars(builder2);
			builder2.clear();
			builder2.setTarIndex(1002).setTarName("水上机").setTarLatitude((float)(100.13))
			.setTarLongitude((float)(87.5)).setTarElevation((float)(122.13)).setTarType(ProtoTarget.Type.SS);
			builder3.addTars(builder2);
		}
		else {
			builder2.setTarIndex(1002).setTarName("无人机").setTarLatitude((float)(90.13))
			.setTarLongitude((float)(110.5)).setTarElevation((float)(1000.13)).setTarType(ProtoTarget.Type.KZ);
			builder3.addTars(builder2);		
		}
		ProtoTarget.Targets targets=builder3.build();
		byte[]b=targets.toByteArray();
		System.out.println("输出333333     " + b);
		return b;
	}
}
